
**************************************************************************
*Appendix Table 7. Descriptive statistics of occupations and work units of 
*			 	 low-educated migrants and urban resident in 1993 and 2015 
**************************************************************************

version 15.1
cd "${mypath}\CHNS_project\01_data\02_posted\"

log using "${mypath}\CHNS_project\03_log_files\11_appendix_table_6.log", replace

use CHNS_1993_2015_20_imputed.dta,clear
mi import ice, automatic

*generate exclusion condition, that is, people who work in agriculture in urban area
gen be_farmer = (migrant_group != 2 & occupation == 3 & work_unit == 4) if be_employed == 1

*generate occupations
tab occupation if be_employed == 1 ,gen(occ)
la var occ1 "professional or technical worker"
la val occ1 occ1
la var occ2 "officer"
la val occ2 occ2
la var occ3 "farmer fisherman and hunter"
la val occ3 occ3
la var occ4 "skilled worker"
la val occ4 occ4
la var occ5 "non-skilled worker"
la val occ5 occ5
la var occ6 "service worker"
la val occ6 occ6
la var occ7 "other(including homemaker)"
la val occ7 occ7

*generate working units
gen unit1 = 1 if work_unit == 1
replace unit1 = 0 if mi(unit1) & work_unit != 0
gen unit2 = 1 if work_unit == 2 | work_unit == 3
replace unit2 = 0 if mi(unit2) & work_unit != 0
gen unit3 = 1 if work_unit == 4 | work_unit == 5
replace unit3 = 0 if mi(unit3) & work_unit != 0
la var unit1 "goverment"
la val unit1 unit1
la var unit2 "public enterprise"
la val unit2 unit2
la var unit3 "private enterprise"
la val unit3 unit3 

local path "${mypath}\CHNS_project\04_tables\appendix_table_7\"

foreach wave of numlist 1993 2015 {
	misum occ1 occ2 occ3 occ4 occ5 occ6 occ7 unit1 unit2 unit3 if time != 1 & be_farmer != 1 & be_migrant == 1 & wave == `wave' & degree_education <= 3 & be_employed == 1,matrix(migrant_`wave')
	matrix migrant_`wave' = r(migrant_`wave')
	putexcel set "`path'\migrant_`wave'.xlsx", modify
	putexcel A1 = matrix(migrant_`wave'), names

	misum occ1 occ2 occ3 occ4 occ5 occ6 occ7 unit1 unit2 unit3 if time != 1 & be_farmer != 1 & be_urban_resident == 1 & wave == `wave' & degree_education <= 3 & be_employed == 1,matrix(urban_`wave')
	matrix urban_`wave' = r(urban_`wave')
	putexcel set "`path'\urban_`wave'.xlsx", modify
	putexcel A1 = matrix(urban_`wave'), names
}

log close
